package com.cnpc.rightslogan.service.impl;

import com.cnpc.rightslogan.entity.DictionaryData;
import com.cnpc.rightslogan.mapper.DictionaryDataMapper;
import com.cnpc.rightslogan.service.IDictionaryDataService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class DictionaryDataServiceImpl implements IDictionaryDataService {

    @Resource
    private DictionaryDataMapper dictionaryDataMapper;

    @Override
    public DictionaryData getDictionaryData(int id) {
        DictionaryData dictionaryData = new DictionaryData();
        dictionaryData.setDicDataId(id);
        return dictionaryDataMapper.selectOne(dictionaryData);
    }

    @Override
    public DictionaryData getDictionaryData(DictionaryData dictionaryData) {
        return dictionaryDataMapper.selectOne(dictionaryData);
    }

    @Override
    public PageInfo<DictionaryData> getDictionaryDataList(Integer pageNum, Integer pageSize, DictionaryData dictionaryData) {
        PageHelper.startPage(pageNum, pageSize);
        List<DictionaryData> dictionaryDataList = dictionaryDataMapper.select(dictionaryData);
        return new PageInfo<>(dictionaryDataList);
    }

    @Override
    public Integer addDictionaryData(DictionaryData dictionaryData) {
        return dictionaryDataMapper.insert(dictionaryData);
    }

    @Override
    public Integer updateDictionaryData(DictionaryData dictionaryData) {
        return dictionaryDataMapper.updateByPrimaryKeySelective(dictionaryData);
    }

    @Override
    public Integer deleteDictionaryData(DictionaryData dictionaryData) {
        return dictionaryDataMapper.delete(dictionaryData);
    }
}